package ro.cityprojects.adminloc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import ro.cityprojects.adminloc.entities.Association;
import ro.cityprojects.adminloc.exceptions.ValidationException;
import ro.cityprojects.adminloc.service.AssociationService;

import javax.validation.Valid;

/**
 * AssociationsController class
 *
 * @author bogdan.solga
 *
 * Date: 14.06.2013, time: 17:34
 */
@Controller
@RequestMapping(value = "/associations")
public class AssociationsController extends BaseController<Integer, Association>  {

    @Autowired
    private AssociationService associationService;

    @Override
    public void save(@RequestBody Association entity) throws ValidationException {
        associationService.checkExisting(entity);
        associationService.save(entity);
    }

    @Override
    public String get(@PathVariable Integer id, @RequestParam(required = false) String includedFields) {
        return associationService.get(id, includedFields);
    }

    @Override
    public String get(@RequestParam(required = false) String name, @RequestParam(required = false) String value,
                      @RequestParam(required = false) String includedFields) {
        return associationService.getAll(name, value, includedFields);
    }

    @Override
    public void update(@Valid @RequestBody Association entity, @PathVariable Integer id) {
        associationService.update(entity, id);
    }

    @Override
    public void delete(@PathVariable Integer primaryKey) {
        associationService.delete(primaryKey);
    }

    @Override
    public String getMetadata() {
        return associationService.getMetadata();
    }
}
